/**
* Javascipt Library for calendar
* @Ray Li
* dependency
  <!-- calendar stylesheet -->
  <link rel="stylesheet" type="text/css" media="all" href="js/components/ui/calendar_style/calendar-blue.css" title="win2k-cold-1" />

  <!-- main calendar program -->
  <script type="text/javascript" src="js/components/ui/calendar.js"></script>

  <!-- language for the calendar -->
  <script type="text/javascript" src="js/components/ui/calendar_lang/cn_utf8.js"></script>

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="js/components/ui/calendar-setup.js"></script>
*/

  function CalendarUtil(inputname) {
      // property define
      this.inputname = "date";
      this.classname = "validate-date-cn";
      this.readonly = "";
      this.imgpath = "/hr/images/calendar.gif";
      this.validateFailedMessage = "";
      
      if(inputname) this.inputname = inputname;
      
      this.fdate = "f_date_" + this.inputname;
      this.ftrigger = "f_trigger_" + this.inputname;
      // method define
      this.drawCalendar = function(){
          var sCalendarHtml = "";
          if(Validation){
              //sCalendarHtml =
                  //"<table cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse: collapse\"><tr>" +
                      //"<td><input onchange=\"Validation.validate(this)\" type=\"text\" class=\"" + this.classname + "\" name=\"" + this.inputname + "\" id=\""+ this.fdate +"\" " + this.readonly + " validateFailedMessage=\"" + this.validateFailedMessage + "\" precedingElm=\""+ this.ftrigger +"\"/></td>" +
                      //"<td><img src=\"" + this.imgpath + "\" id=\""+ this.ftrigger +"\" style=\"cursor: pointer; border: 1px solid red;\" title=\"Date selector\"" +
                      //"onmouseover=\"this.style.background='red';\" onmouseout=\"this.style.background=''\" /></td>" +
                  //"</table>";
              sCalendarHtml =
                  "<div class=\"calendarEventEditor\"><TABLE cellSpacing=0 cellPadding=0><TR>" +
                      "<TD><INPUT onchange=\"Validation.validate(this)\" type=\"text\" class=\"" + this.classname + "\" name=\"" + this.inputname + "\" id=\""+ this.fdate +"\" " + this.readonly + " validateFailedMessage=\"" + this.validateFailedMessage + "\"  maxLength=10 advicePrecedingElm=\"failedAdvice" + this.inputname + "\"/></TD>" +
                      "<TD style=\"POSITION: relative\"><DIV class=\"eventDatePicker\">" +
	                  "<DIV class=\"dateIcon\" title=选择日期 id=\""+ this.ftrigger +"\"></DIV></DIV></TD>" +
	                  "<TD><span id=\"failedAdvice" + this.inputname + "\"></span></TD></TR>" +
                  "</TABLE></div>"
          }else{
              //sCalendarHtml =
                  //"<table cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse: collapse\"><tr>" +
                      //"<td><input type=\"text\" class=\"" + this.classname + "\" name=\"" + this.inputname + "\" id=\""+ this.fdate +"\" " + this.readonly + " /></td>" +
                      //"<td><img src=\"" + this.imgpath + "\" id=\""+ this.ftrigger +"\" style=\"cursor: pointer; border: 1px solid red;\" title=\"Date selector\"" +
                      //"onmouseover=\"this.style.background='red';\" onmouseout=\"this.style.background=''\" /></td>" +
                  //"</table>"; 
              sCalendarHtml =
                  "<div class=\"calendarEventEditor\"><TABLE cellSpacing=0 cellPadding=0><TR>" +
                      "<TD><INPUT type=\"text\" class=\"" + this.classname + "\" name=\"" + this.inputname + "\" id=\""+ this.fdate +"\" " + this.readonly + " validateFailedMessage=\"" + this.validateFailedMessage + "\"  maxLength=10 /></TD>" +
                      "<TD style=\"POSITION: relative\"><DIV class=\"eventDatePicker\">" +
	                  "<DIV class=\"dateIcon\" title=选择日期 id=\""+ this.ftrigger +"\"></DIV></DIV></TD></TR>" +
                  "</TABLE></div>"                           
          }
          document.write(sCalendarHtml);
          this.initCalendar();
      }
      
      this.initCalendar = function(){
          Calendar.setup({
              inputField     :    this.fdate,     // id of the input field
              ifFormat       :    "%Y-%m-%d",      // format of the input field
              button         :    this.ftrigger,  // trigger for the calendar (button ID)
              align          :    "Tl",           // alignment (defaults to "Bl")
              singleClick    :    true
          });    
      }
      
      this.setInputname = function( name ){
          this.inputname = name;
          this.fdate = "f_date_" + name;
          this.ftrigger = "f_trigger_" + name;
      }
      
      this.setReadonly = function( ){
          this.readonly = "readonly";
      }
      
      this.setReadwrite = function( ){
          this.readonly = "";
      }
      
      this.setClassname = function( classname ){
          this.classname = "validate-date-cn " + classname;
      }
      
      this.setFailedMessage = function( message ){
          this.validateFailedMessage = message;
      }
      
             
  }
   
  var calendarUtil = new CalendarUtil();